// #include"searcher.hpp"
#include "cpp-httplib/httplib.h"
#include"searcher.hpp"
const std::string path = "./wwwroot";
const std::string input = "data/raw_html/raw.txt";
int main()
{
    //创建searcher对象
    ns_searcher::Searcher searcher;
    //初始化索引
    searcher.InitSearcher(input);
	httplib::Server svr;
    //设置根目录
	svr.set_base_dir(path.c_str());
    //设置输入内容，并设置输出结果,如果没有输入内容（只有地址和端口号），会直接显示根目录的内容
	svr.Get("/s", [&searcher](const httplib::Request &req, httplib::Response &rsp)
			{
		if(!req.has_param("word"))		
		{
			rsp.set_content("请输入关键字","text/plain;charset=utf-8");
			return;
		}
		std::string s = req.get_param_value("word");
        std::string json_string;
        searcher.Search(s,&json_string);
        //需要输出的内容
  		rsp.set_content(json_string.c_str(), "application/json"); });

	svr.listen("0.0.0.0", 8081);
	// httplib::Server sver;
	// sver.Get("hi/",[](const httplib::Request& req,httplib::Response& rep){
	//		rep.set_content("你好，世界！","text/plain; charset=utf-8");
	//		});
	// sver.listen("0.0.0.0",8080);
	return 0;
}
